let arr = ['1', '2', '3', '4', '5', '6']
function take(string, total, list) {
  for (let i = 0; i < list.length; i++) {
    let temp = [...list]
    let n = temp.splice(i, 1) + string
    if (total == 1) {
      console.log(n)
    } else {
      take(n, total - 1, temp)
    }
  }
}
take('', 5, arr)
/*
  take('',4,arr)
    i=0
    string = ''
    total = 4
    list = arr
    temp = ['1', '2', '3', '4', '5']
    n = ['1'] + '' = '1'
    temp = ['2', '3', '4', '5']

    take('1',3,['2', '3', '4', '5'])
      i = 0
      string = '1'
      total = 3
      temp = ['2', '3', '4', '5']
      n = ['2']+1 = '21'
      temp = ['3', '4', '5']
    take('21', 2, ['3', '4', '5'])
      i = 0
      string = '21'
      total = 2
      temp = ['3', '4', '5']
      n = ['3']+'21' = '321'
      temp = ['4', '5']
    take('321', 1, ['4', '5'])
      i = 0
      string = '321'
      total = 1
      temp = ['4', '5']
      n = ['4']+'321' = '4321'
      temp = ['5']
*/
